<?php
namespace App\Http\Controllers\ApiWx;

use App\DBs\CommentDB;
use Illuminate\Http\Request;

class PlController extends BaseController
{
    //评论

    protected $db;

    public function __construct()
    {
        parent::__construct();
        $this->db = new CommentDB();
    }

    /**
     * 列表
     */
    public function getIndex(Request $request)
    {
        $wx = $request->post('wx','');
        $vid = $request->post('vid',0);
        $resDb = $this->db->getIndex($wx,$vid);
        if ($resDb['code']!=0) {
            return $this->toWxJson(-3);
        }
        $items = $resDb['data']; $total = $resDb['total'];
        return $this->toWxJson(0,$items,$total);
    }

    /**
     * 新增
     */
    public function setAdd(Request $request)
    {
        $wx = $request->post('wx','');
        $vid = $request->post('vid',0);
        $txt = $request->post('txt','');
        if (!$vid || !$txt) {
            return $this->toWxJson(-2);
        }
        $resDb = $this->db->setAdd($wx,$vid,$txt);
        if ($resDb['code']!=0) {
            return $this->toWxJson(-500);
        }
        return $this->toWxJson(0);
    }
}